package com.cai.servlet.common.topic;

import com.cai.dao.DetailedTopicDao;
import com.cai.dao.impl.DetailedTopicDaoImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author RuoLi
 * 更换题目类型显示
 */
@WebServlet(name = "ServletDetailedTopicChangeInfo", value = "/common/DetailedTopicChangeInfo")
public class ServletDetailedTopicChangeInfo extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        DetailedTopicDao detailedTopicDao = new DetailedTopicDaoImpl();
        req.setCharacterEncoding("utf-8");
        resp.setContentType("text/html;charset=utf-8");
        String topicType = req.getParameter("topic_type");
        String repCurrentPage = req.getParameter("currentPage");
        String reqPageSize = req.getParameter("pageSize");
        String data = detailedTopicDao.getDetailedTopicInfoUserClientChangeTopicType(topicType, Integer.parseInt(repCurrentPage), Integer.parseInt(reqPageSize));
        resp.getWriter().write(data);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //获取分页数据
        req.setCharacterEncoding("utf-8");
        resp.setContentType("text/html;charset=utf-8");
        String topicType = req.getParameter("topic_type");
        String pageSize = req.getParameter("pageSize");
        DetailedTopicDao detailedTopicDao = new DetailedTopicDaoImpl();
        String data= detailedTopicDao.getDetailedTopicChoseTopicType(Integer.parseInt(pageSize),topicType);
        resp.getWriter().write(data);
    }
}
